package demo2;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class Util {
    private static volatile JedisPool pool;//要让该对象是单例
    private Util(){}
    //获取池子
    public static JedisPool getInstance(){
        if(null==pool){
            synchronized (Util.class){
                if(null==pool){
                    JedisPoolConfig cfg=new JedisPoolConfig();
                    cfg.setMaxActive(1000);
                    cfg.setMaxIdle(32);
                    cfg.setMaxWait(100*1000);
                    pool=new JedisPool(cfg,"192.168.184.100",6379);
                }
            }
        }
        return pool;
    }

    //不使用时，把连接放回池子
    public static void release(JedisPool pool, Jedis j){
        if(null!=j){
            pool.returnResourceObject(j);
        }
    }


}
